﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RunCircle
{
    public class PlayerStatus
    {
        public virtual void Enter(Player pplayer)
        {
            ;
        }

        public virtual void Execute(Player pplayer)
        {
            ;
        }

        public virtual void Exit(Player pplayer)
        {
            ;
        }
    }

    public class Player_Run : PlayerStatus
    {
        public static Player_Run Instance()
        {
            if (m_instance == null)
            {
                m_instance = new Player_Run();
            }
	        return m_instance;
        }

        public override void Enter(Player pplayer)
        {
            pplayer.jumpOver();
            pplayer.startRun();
        }

        public override void Execute(Player pplayer)
        {
            //这里检测，如果碰到障碍，转到fall态
            //pplayer.m_FSM.SetPlayerStatus(Player_Fall.Instance());
            //如果抓到进入停止态，设置谁被抓了
            //pplayer.m_FSM.SetPlayerStatus(Player_Stop.Instance());
        }

        public override void Exit(Player pplayer)
        {
            ;
        }

        private static Player_Run m_instance;
    }

    public class Player_Jump : PlayerStatus
    {
        public static Player_Jump Instance()
        {
            if (m_instance == null)
            {
                m_instance = new Player_Jump();
            }
            return m_instance;
        }

        public override void Enter(Player pplayer)
        {
            pplayer.jump();
        }

        public override void Execute(Player pplayer)
        {
            pplayer.jumpUpStep();
            if (pplayer.isCurJumpHeightOverMax())
            {
                pplayer.m_FSM.SetPlayerStatus(Player_JumpDown.Instance());
            }
        }

        public override void Exit(Player pplayer)
        {
            ;
        }

        private static Player_Jump m_instance;
    }

    public class Player_JumpDown : PlayerStatus
    {
        public static Player_JumpDown Instance()
        {
            if (m_instance == null)
            {
                m_instance = new Player_JumpDown();
            }
            return m_instance;
        }

        public override void Enter(Player pplayer)
        {
            ;
        }

        public override void Execute(Player pplayer)
        {
            pplayer.jumpDownStep();
            if (pplayer.isCurJumpHeightOverZero())
            {
                pplayer.m_FSM.SetPlayerStatus(Player_Run.Instance());
            }
        }

        public override void Exit(Player pplayer)
        {
            pplayer.jumpOver();
        }

        private static Player_JumpDown m_instance;
    }

    public class Player_Fall : PlayerStatus
    {
        public static Player_Fall Instance()
        {
            if (m_instance == null)
            {
                m_instance = new Player_Fall();
            }
            return m_instance;
        }

        public override void Enter(Player pplayer)
        {
            //1 停止移动
            pplayer.stopRun();
            //2 播放摔倒动画
            pplayer.playFallAnimation();

            pplayer.jumpOver();
        }

        public override void Execute(Player pplayer)
        {
            //如果摔倒动画播放完毕，转入跑步态
            //pplayer.m_FSM.SetPlayerStatus(Player_Run.Instance());
            //如果抓到进入停止态，设置谁被抓了
            //pplayer.m_FSM.SetPlayerStatus(Player_Stop.Instance());
        }

        public override void Exit(Player pplayer)
        {
            ;
        }

        private static Player_Fall m_instance;
    }

    public class Player_Electric : PlayerStatus
    {
        public static Player_Electric Instance()
        {
            if (m_instance == null)
            {
                m_instance = new Player_Electric();
            }
            return m_instance;
        }

        public override void Enter(Player pplayer)
        {
            //1 停止移动
            pplayer.stopRun();
            //2 播放摔倒动画
            pplayer.playElectricAnimation();

            pplayer.jumpOver();
        }

        public override void Execute(Player pplayer)
        {
        }

        public override void Exit(Player pplayer)
        {
            ;
        }

        private static Player_Electric m_instance;
    }

    public class Player_SpeedUp : PlayerStatus
    {
        public static Player_SpeedUp Instance()
        {
            if (m_instance == null)
            {
                m_instance = new Player_SpeedUp();
            }
            return m_instance;
        }

        public override void Enter(Player pplayer)
        {
            //加速跑
            pplayer.speedUpRun();
            //播放加速动画
        }

        public override void Execute(Player pplayer)
        {
            pplayer.speedUpStep();
            if (pplayer.getSpeedUpCurTime() <=0 )
            {
                pplayer.m_FSM.SetPlayerStatus(Player_Run.Instance());
            }
        }

        public override void Exit(Player pplayer)
        {
            pplayer.speedUpOver();
        }

        private static Player_SpeedUp m_instance;
    }

    public class Player_Anger : PlayerStatus
    {
        public static Player_Anger Instance()
        {
            if (m_instance == null)
            {
                m_instance = new Player_Anger();
            }
            return m_instance;
        }

        public override void Enter(Player pplayer)
        {
            //无敌跑
            pplayer.angerRun();
        }

        public override void Execute(Player pplayer)
        {
            pplayer.angerStep();
            if (pplayer.getAngerCurTime() <= 0)
            {
                pplayer.m_FSM.SetPlayerStatus(Player_Run.Instance());
            }
        }

        public override void Exit(Player pplayer)
        {
            pplayer.angerOver();
        }

        private static Player_Anger m_instance;
    }
        //赢了
    public class Player_Win : PlayerStatus
    {
        public static Player_Win Instance()
        {
            if (m_instance == null)
            {
                m_instance = new Player_Win();
            }
            return m_instance;
        }

        public override void Enter(Player pplayer)
        {
            pplayer.jumpOver();
            pplayer.winGame();
        }

        public override void Execute(Player pplayer)
        {
        }

        public override void Exit(Player pplayer)
        {
            ;
        }

        private static Player_Win m_instance;
    }
    //输了
    public class Player_Lose : PlayerStatus
    {
        public static Player_Lose Instance()
        {
            if (m_instance == null)
            {
                m_instance = new Player_Lose();
            }
            return m_instance;
        }

        public override void Enter(Player pplayer)
        {
            pplayer.jumpOver();
            pplayer.loseGame();
        }

        public override void Execute(Player pplayer)
        {
        }

        public override void Exit(Player pplayer)
        {
            ;
        }
        private static Player_Lose m_instance;
    }

    public class Player_Stop : PlayerStatus
    {
        public static Player_Stop Instance()
        {
            if (m_instance == null)
            {
                m_instance = new Player_Stop();
            }
            return m_instance;
        }

        public override void Enter(Player pplayer)
        {
            pplayer.stopRun();
        }

        public override void Execute(Player pplayer)
        {
            ;
        }

        public override void Exit(Player pplayer)
        {
            ;
        }

        private static Player_Stop m_instance;
    }
}
